<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<object>>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Deck - <%= ViewData["Since"] %> to <%= ViewData["To"] %></title>
    <link rel="Stylesheet" href="../../Content/Site.css" />
</head>
<body>
    <div>
        <a href="/"><img style="border-style: none" src="../../Content/img/logo.png" /></a>
    </div>
    <div class="users">
    <% foreach (var u in (ViewData["Users"] as IEnumerable<TheWorldsWorst.StackOverflowClone.Controllers.UserPair>))
       { %>
        <div class="user">
            <a href="/users/<%= u.Id %>"><%= u.Name%></a> - <a class="remove" href="/deck?userId=<%= u.Id %>&remove=true">X</a>
        </div>
    <% } %>
    </div>
    <br />
    <div class="control">
        <form method="get" action="/deck">
            Add User Id: <input type="text" name="userId" /><br />
            Since: <input type="text" name="since" value="<%= ViewData["Since"] %>" /><br />
            To: <input type="text" name="to" value="<%= ViewData["To"] %>" /><br />
            <input type="submit" value="Update" />
        </form>
    </div>
    <div>
        Recent Activity of the users you are following.
    </div>
    <table width="80%">
    <tr>
        <td><b>User Activity</b></td>
        <td><b>Favorite Activity</b></td>
        <td><b>Comment Mentions</b></td>
    </tr>
            <% var uevts = Model.Where(p => p is TheWorldsWorst.ApiWrapper.Model.UserEvent).Cast<TheWorldsWorst.ApiWrapper.Model.UserEvent>().AsEnumerable().GetEnumerator();
               var pevts = Model.Where(p => p is TheWorldsWorst.ApiWrapper.Model.PostEvent).Cast<TheWorldsWorst.ApiWrapper.Model.PostEvent>().AsEnumerable().GetEnumerator();
               var cevts = Model.Where(p => p is TheWorldsWorst.ApiWrapper.Model.Comment).Cast<TheWorldsWorst.ApiWrapper.Model.Comment>().AsEnumerable().GetEnumerator();

               bool U, P, C;
                
               // | doesn't short-ciruit, || does; so I'm use | in this case
               while ((U = uevts.MoveNext()) | (P = pevts.MoveNext()) | (C = cevts.MoveNext()))
               {
                   %>
                   <tr>
                   <td>
                   <%
                var uevt = uevts.Current;
                var pevt = pevts.Current;
                var cevt = cevts.Current;
                if (U)
                {
            %>
                <div class="event">
                    <a href="/users/<%= uevt.UserId %>"><%= uevt.UserName%></a><br />
                    <%= uevt.Action%><br />
                    <%= uevt.Description%><br />
                    <%= uevt.Detail%><br />
                    <%= uevt.PostId ?? uevt.CommentId%><br />
                    <%= uevt.Ago%>
                </div>   
                <% }
                   %></td><td><%
                if (P)
                {   
                %>
                <div class="favorite">
                    <% if (pevt.UserId.HasValue)
                       { %>
                    <a href="/users/<%= pevt.UserId %>"><%= TheWorldsWorst.ApiWrapper.ApiProxy.GetUserFor(pevt.UserId.Value).Name%></a><br />
                    <% } %>
                    <%= pevt.Action%><br />
                    <%= pevt.ActionUserId%><br />
                    <a href="/postredirect/<%= pevt.PostId %>">Post</a><br />
                    <%= Enum.GetName(typeof(TheWorldsWorst.ApiWrapper.Model.PostEventType), pevt.PostTimelineType)%><br />
                    <%= pevt.Ago%>
                </div>
                 <% } %>
                   </td>
                   <td>
                   <% if (C)
                      { %>
                        <div class="comment">
                            <a href="/users/<%= cevt.UserId %>"><%= cevt.UserDisplayName%></a><br />
                            <%= cevt.VoteCount%><br />
                            <%= cevt.Body%>
                            <a href="/postredirect/<%= cevt.PostId %>">Post</a><br />
                            <%= cevt.Ago%>
                        </div>
                   <% } %>
                   </td>
                   </tr>
            <% } %>
     </table>
</body>
</html>
